<template>
    <div class="admin-container">
      <!-- 左侧导航栏 -->
      <div class="sidebar">
        <div class="logo-container">
          <el-icon class="logo-icon"><Platform /></el-icon>
          <h1>驾校考试系统</h1>
        </div>
        <el-menu
          :default-active="defaultPath"
          router
          background-color="#2c3e50"
          text-color="#b7c4d1"
          active-text-color="#409EFF"
          class="el-menu-vertical"
        >
          <el-menu-item index="/Home">
            <el-icon><House /></el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="/students">
            <el-icon><UserFilled /></el-icon>
            <span>学员管理</span>
          </el-menu-item>
          <el-sub-menu index="/questions">
            <template #title>
              <el-icon><DocumentCopy /></el-icon>
              <span>试题管理</span>
            </template>
            <el-menu-item index="/single-choice">
              <el-icon><CircleCheck /></el-icon>
              <span>单选题</span>
            </el-menu-item>
            <el-menu-item index="/judgement">
              <el-icon><Check /></el-icon>
              <span>判断题</span>
            </el-menu-item>
            <el-menu-item index="/short-answer">
              <el-icon><EditPen /></el-icon>
              <span>简答题</span>
            </el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="/exams">
            <template #title>
              <el-icon><Notebook /></el-icon>
              <span>考试管理</span>
            </template>
            <el-menu-item index="/exam-papers">
              <el-icon><Files /></el-icon>
              <span>考试试卷</span>
            </el-menu-item>
            <el-menu-item index="/question-settings">
              <el-icon><Setting /></el-icon>
              <span>考试设置</span>
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
  
      <!-- 主内容区域 -->
      <div class="main-content">
        <div class="header">
          <div class="user-info">
            <el-dropdown>
              <span class="el-dropdown-link">
                <el-avatar :size="36" :src="userAvatar" />
                <span class="username">{{ userName }}</span>
                <el-icon class="el-icon--right"><arrow-down /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>个人中心</el-dropdown-item>
                  <el-dropdown-item>修改密码</el-dropdown-item>
                  <el-dropdown-item divided @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
        <div class="content-wrapper">
          <router-view></router-view>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  import { 
    Platform, House, UserFilled, DocumentCopy, CircleCheck,
    Check, EditPen, Notebook, Files, Setting, ArrowDown
  } from '@element-plus/icons-vue'
  
  export default {
    name: "AdminLayout",
    components: {
      Platform, House, UserFilled, DocumentCopy, CircleCheck,
      Check, EditPen, Notebook, Files, Setting, ArrowDown
    },
    setup() {
      const router = useRouter()
      const defaultPath = ref(router.currentRoute.value.path)
      
      const userName = ref('管理员')
      const userAvatar = ref('https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png')
      
      const logout = () => {
        router.push('/login')
      }
      
      return {
        defaultPath,
        userName,
        userAvatar,
        logout
      }
    }
  }
  </script>
  
  <style scoped>
  .admin-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
  }
  
  .sidebar {
    width: 220px;
    background-color: #2c3e50;
    color: #fff;
    transition: width 0.3s;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.1);
    z-index: 10;
  }
  
  .logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .logo-icon {
    font-size: 24px;
    margin-right: 10px;
    color: #409EFF;
  }
  
  .sidebar h1 {
    font-size: 18px;
    margin: 0;
    white-space: nowrap;
  }
  
  .el-menu-vertical {
    border-right: none;
  }
  
  .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #f5f7fa;
  }
  
  .header {
    height: 60px;
    background-color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 20px;
  }
  
  .user-info {
    display: flex;
    align-items: center;
  }
  
  .el-dropdown-link {
    display: flex;
    align-items: center;
    cursor: pointer;
  }
  
  .username {
    margin: 0 10px;
    font-size: 14px;
  }
  
  .content-wrapper {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
  }
  
  /* 响应式调整 */
  @media (max-width: 768px) {
    .sidebar {
      width: 64px;
    }
    
    .sidebar h1 {
      display: none;
    }
    
    .logo-icon {
      margin-right: 0;
    }
  }
  </style>